﻿using EmprestaAE.MVVM.Model;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml.Data;

namespace EmprestaAE.Common
{
    class ConverterDateToString : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {

            DateTime date;
            string datestring = string.Empty;

            if (value != null)
            {
                if (parameter != null)
                {
                    if (parameter.ToString().Equals("Revert"))
                    {
                        date = ((DateTime)value);
                        datestring = date.ToString(DateTimeFormatInfo.CurrentInfo.ShortDatePattern);
                    }                    
                }
                else
                {
                    bool isdate = DateTime.TryParse((value as DateModel).Date.ToString(), out date);

                    if (isdate)
                    {
                        datestring = date.ToString(DateTimeFormatInfo.CurrentInfo.ShortDatePattern);
                    }
                }
                
            }

            return datestring;
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }
}
